/*************************************************************************
  Crytek Source File.
  Copyright (C), Crytek Studios, 2001-2010.
 -------------------------------------------------------------------------
  $Id$
  $DateTime$
  
 -------------------------------------------------------------------------
  History:
  - Oct 28th, 2010  : Created by Michelle Martin
 *************************************************************************/

#include "StdAfx.h"
#include "IKTarget_Attachment.h"
#include <IEntitySystem.h>  // for GetEntity() by id
#include <ICryAnimation.h>  // for Attachment interfaces



CIKTarget_Attachment::CIKTarget_Attachment(const SIKTargetParams& ikParams, QuatT &startPosition, EntityId targetEntityID, const char* attachmentName) : CIKTarget_Base(ikParams, startPosition)
{
	IEntity* targetEntity = gEnv->pEntitySystem->GetEntity(targetEntityID);
	if (!targetEntity)
		CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_ERROR, "IK Target: Invalid Entity ID for Attachment Target, this will cause the IK to crash when used with this");

	if (attachmentName == NULL || attachmentName == '\0')
		CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_ERROR, "IK Target: No Attachment Name specified - this won't work with the IK when this target is used.");


	ICharacterInstance* pCharacterInstance = targetEntity->GetCharacter(0);
	IAttachmentManager* pAttachmentManager = pCharacterInstance->GetIAttachmentManager();
	if (!pAttachmentManager)
	{
		CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_ERROR, "IK Target: No Attachment Manager found, cannot retrieve Attachment for IK. IK will fail or look weird.");
		return;
	}

	m_attachment = pAttachmentManager->GetInterfaceByName(attachmentName);
	if (m_attachment == NULL)
		CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_ERROR, "IK Target: Attachment with name %s not found. IK will crash when executed.", attachmentName);
}

// ===========================================================================

QuatT CIKTarget_Attachment::UpdateWorldPos( float frameTime )
{
	CRY_ASSERT_MESSAGE(m_attachment, "IK Target: Attachment invalid. Will crash.");

	return m_attachment->GetAttWorldAbsolute();
}


// ===========================================================================






